exports.transTime = function (val) {
  var date = '';
  if (val) {
    date = new Date(val);
  } else {
    date = new Date();
  };
  var Y = date.getFullYear();
  var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
  var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
  var h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
  var m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes() ;
  var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
  return Y + '-' + M + '-' + D + ' ' + h + ':' + m + ':' + s; 
}

exports.timeDown = function (val) {
  var nowTime = new Date();
  var createdTime = new Date(val);
  if (nowTime - createdTime < 0 || nowTime - createdTime > 1800000) {
    return 0;
  };
  var differ = nowTime - createdTime;
  differ = 1000 * 60 * 30 - differ;
  var minute = Math.floor(differ / 60000);
  minute = minute < 10 ? '0' + minute : minute;
  var second = Math.floor((differ - minute * 60000) / 1000);
  second = second < 10 ? '0' + second : second;
  var resulte = minute + ':' + second;
  if (minute == NaN || second == NaN) {
    resulte = 0;
  }
  return minute + ':' + second;
}

// 获取今天的时间
exports.toDayTime = function () {
  var times = new Date();
    var year = times.getFullYear();
    var month = times.getMonth() < 10 ? '0' + (times.getMonth() + 1) : (times.getMonth() + 1);
    var day = times.getDate() < 10 ?  '0' + times.getDate() : times.getDate();
    return year + '-' + month + '-' + day;
}

// 获取目标月的天数
exports.getCountDays = function(time) {
  var curDate = new Date(time);
  /* 获取当前月份 */
  var curMonth = curDate.getMonth();
  /*  生成实际的月份: 由于curMonth会比实际月份小1, 故需加1 */
  curDate.setMonth(curMonth + 1);
  /* 将日期设置为0, 这里为什么要这样设置, 我不知道原因, 这是从网上学来的 */
  curDate.setDate(0);
  /* 返回当月的天数 */
  return curDate.getDate();
}